package com.valentinalee.bms.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MybatisSqlSessionUtil {


	/**
	 * 获取sqlSession
	 * 
	 * @return
	 */
	public static SqlSession getSqlSession() {
		// 1.定义需要去加载的mybatis配置文件
		String mybatisConfigFile = "mybatis-config.xml";

		try {
			InputStream is = Resources.getResourceAsStream(mybatisConfigFile);// 定义当前方法返回的变量快捷键:Shift+Alt+L
			SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
					.build(is);
			SqlSession session = sqlSessionFactory.openSession();
			return session;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

}
